﻿
/*******************************************************************************************/
/***************** DETENER LOS BOTONES DE ATRÁS Y ADELANTE DEL BROWSER *********************/
/*******************************************************************************************/

//window.history.forward(1);
//window.history.back(1);


/*******************************************************************************************/
/*******************************************************************************************/

var __CalContenedor = "";
var __CalTextBox = "";
var __CalX = 0;
var __CalY = 0;

/*******************************************************************************************/
/*******************************   CALENDARIO PERIODO   ************************************/
/*******************************************************************************************/

function CalendarioPeriodo(oimg, idinput) {
    var idcal = "cal_" + idinput;
    var top = oimg.offsetTop;
    var left = oimg.offsetLeft;
    oimg.style.cursor = "pointer";
    if (document.getElementById(idinput)) {
        oimg.onmousemove = function () {
            var e = window.event;
            if (e.type == "mousemove") {
                __CalX = e.clientX + left;
                __CalY = e.clientY + top;
            }
        }
        oimg.onclick = function () {
            __CalTextBox = idinput;
            CrearCalendarioPeriodo(__CalY, __CalX);
        }
    }
}

function CerrarCalendarioPeriodo() {
    if (document.getElementById(__CalContenedor)) {
        document.body.removeChild(document.getElementById(__CalContenedor));
    }
}

function CrearCalendarioPeriodo(imgt, imgl) {

    CerrarCalendarioPeriodo();

    var divwidth = 170;
    var divheight = 180;
    var bodyw = parseInt(document.body.scrollWidth);
    var bodyh = parseInt(document.body.scrollHeight) + 20;
    var divcal = document.createElement("div");
    divcal.id = "CFCalendar";
    divcal.style.position = "relative";

    /*******************************************/
    divcal.style.position = "absolute";
    var dctop = 0;
    var dcleft = 0;

    dctop = imgt - (divheight * 0.1);
    dcleft = imgl - divwidth;

    if (window.parent.document.getElementById("btnc")) {
        if (bodyh < (imgt + divheight)) {
            dctop = bodyh - divheight;
        }
    }

    divcal.style.top = dctop + "px";
    divcal.style.left = dcleft + "px";
    /*******************************************/
    
    divcal.style.width = divwidth + "px";
    divcal.style.height = divheight + "px";

    __CalContenedor = divcal.id
    document.body.appendChild(divcal);

    var hoy = new Date();
    var hoyanio = hoy.getFullYear();
    var hoymes = hoy.getMonth();
    var hoydia = hoy.getDay();

    GenerarCalendarioPeriodo(hoyanio, hoymes, hoydia);
}

function GenerarCalendarioPeriodo(anio, mes, dia) {

    var hoy = new Date();
    var hoyanio = hoy.getFullYear();
    var hoymes = hoy.getMonth();
    var hoydia = hoy.getDate();

    var fecha = new Date(anio, mes, dia);
    var fechaanio = fecha.getFullYear();
    var fechames = fecha.getMonth();
    var fechadia = fecha.getDate();

    var fechadiasem = fecha.getDay();

    var fecha2 = new Date(anio, mes, 1);
    var fecha2anio = fecha2.getFullYear();
    var fecha2mes = fecha2.getMonth();
    var fecha2dia = fecha2.getDate();

    var fecha2diasem = fecha2.getDay();

    var ArrMes = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Setiembre", "Octubre", "Noviembre", "Diciembre");
    var ArrDias = new Array("Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo");

    var ultdia = getLastDay(anio, mes, dia);

    var str = "";

    var MesAnterior = "";
    var MesActual = "";
    var MesPosterior = "";
    var nMesAnterior = 0;
    var nMesActual = 0;
    var nMesPosterior = 0;
    var nAnioAnterior = 0;
    var nAnioActual = 0;
    var nAnioPosterior = 0;

    nMesAnterior = mes;
    nMesActual = mes;
    nMesPosterior = mes;
    nAnioAnterior = anio;
    nAnioActual = anio;
    nAnioPosterior = anio;

    MesAnterior = ArrMes[mes];
    MesActual = ArrMes[mes];
    MesPosterior = ArrMes[mes];

    nAnioAnterior = nAnioAnterior - 1;
    nAnioPosterior = nAnioPosterior + 1;

    str += "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"
    str += "<tr>";
    str += "<td align='right'>";
    str += "<img id='btnc' title='Cerrar' height='25px' border='0' src='../../Images/x.png' style='cursor:pointer; position:relative; top:11px; left:13px' onclick='CerrarCalendario()' />";
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td>";

    str += "<table class='cajaCeleste' border='0' cellpadding='0' cellspacing='0' width='100%' style='padding-left:3px; padding-right:3px'>"
    str += "<tr>";
    str += "<td align='center' colspan='3' style='padding-left:5px; padding-right:5px; padding-top:5px; padding-bottom:5px; cursor:default'>";
    str += "<span style='color:#00529b; font-size:14px; font-weight:bold'> Año " + nAnioActual + "</span>";
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td align='left' style='padding-left:5px; padding-right:5px; cursor:pointer' onclick='GenerarCalendarioPeriodo(" + nAnioAnterior + "," + nMesAnterior + "," + fechadia + ")'>";
    str += "<span style='color:#00529b; font-size:11px; font-weight:bold'>" + nAnioAnterior + "</span>";
    str += "</td>";
    str += "<td align='right' style='padding-left:5px; padding-right:5px; cursor:pointer' onclick='GenerarCalendarioPeriodo(" + nAnioPosterior + "," + nMesPosterior + "," + fechadia + ")'>";
    str += "<span style='color:#00529b; font-size:11px; font-weight:bold'>" + nAnioPosterior + "</span>";
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td align='center' colspan='3' valign='top'style='padding-bottom:5px'>";
    /*******************************************************************************************/


    var cols = 3;
    var ncol = 0;
    var nrow = 0;
    var ndia = 0;
    var tdspace = 0;
    if (fecha2diasem == 0) { tdspace = 6; }
    else { tdspace = fecha2diasem - 1; }

    str += "<table border='0' cellpadding='1' cellspacing='1' width='100%' >"
    str += "<tr>";
    for (a = 0; a < ArrMes.length; a++) {
        if (ncol == 0) { str += "<tr>"; }
        ncol += 1;
        if (mes == a && anio == hoyanio) {
            str += "<td style='cursor:pointer' onmouseover='sombrear(this,true)' onmouseout='sombrear(this,false)' onclick='getCalFechaPeriodo(" + anio + "," + (a + 1) + "," + dia + ")'>";
            str += "<span style='font-size:8pt; font-weight:bold; color:#000' title='" + ArrMes[a].toUpperCase() + "'>" + ArrMes[a].substring(0, 3) + "</span>";
            str += "</td>";
        }
        else {
            str += "<td style='cursor:pointer' onmouseover='sombrear(this,true)' onmouseout='sombrear(this,false)' onclick='getCalFechaPeriodo(" + anio + "," + (a + 1) + "," + dia + ")'>";
            str += "<span style='font-size:8pt' title='" + ArrMes[a].toUpperCase() + "'>" + ArrMes[a].substring(0, 3) + "</span>";
            str += "</td>";
        }
        if (ncol == (cols)) { str += "</tr>"; ncol = 0; }
    }
    str += "</table>";


    /*******************************************************************************************/
    str += "</td>";
    str += "</tr>";
    str += "</table>";

    str += "</td>";
    str += "</tr>";
    str += "</table>";

    document.getElementById(__CalContenedor).innerHTML = str;
}

function getCalFechaPeriodo(anio, mes, dia) {
    var strfecha = "";
    //if (dia < 10) { strfecha += "0" + dia + "/"; }
    //else { strfecha += dia + "/"; }
    if (mes < 10) { strfecha += "0" + mes + "/"; }
    else { strfecha += mes + "/"; }
    strfecha += anio;
    if (document.getElementById(__CalTextBox)) {
        document.getElementById(__CalTextBox).value = "";
        document.getElementById(__CalTextBox).value = strfecha;
    }
    else {
        alert("No existe " + __CalTextBox);
    }
    CerrarCalendarioPeriodo();
}

/*******************************************************************************************/
/**********************************   CALENDARIO   *****************************************/
/*******************************************************************************************/

function Calendario(oimg, idinput) { 
    var idcal = "cal_" + idinput;
    var top = oimg.offsetTop;
    var left = oimg.offsetLeft;
    oimg.style.cursor = "pointer";
    if (document.getElementById(idinput)) {
        oimg.onmousemove = function () {
            var e = window.event;
            if (e.type == "mousemove") {
                __CalX = e.clientX + left;
                __CalY = e.clientY + top;
            }
        }
        oimg.onclick = function () {
            __CalTextBox = idinput;
            CrearCalendario(__CalY, __CalX);
        }
    }
}

function CerrarCalendario() {
    if (document.getElementById(__CalContenedor)) {
        document.body.removeChild(document.getElementById(__CalContenedor));

        /* Se comento para que no se agrandara el iframe */
        //if (window.parent.document.getElementById("btnc")) {
        //    window.parent.ResizerPantallaIframe(window.parent.__IframeWidth, window.parent.__IframeHeight);
        //}
    }
}

function CrearCalendario(imgt, imgl) {

    CerrarCalendario();

    var divwidth = 170;
    var divheight = 180;
    var bodyw = parseInt(document.body.scrollWidth);
    var bodyh = parseInt(document.body.scrollHeight);
    var divcal = document.createElement("div");
    divcal.id = "CFCalendar";
    divcal.style.position = "relative";

    /*******************************************/
    divcal.style.position = "absolute";
    var dctop = 0;
    var dcleft = 0;

    dctop = imgt - (divheight * 0.1);
    dcleft = imgl - divwidth;

    if (imgl < divwidth) {
        dcleft = 0;
    }

    if (window.parent.document.getElementById("btnc")) {
        if (bodyh > divheight) {
            if (bodyh < (imgt + divheight)) {
                dctop = bodyh - divheight;
            }
        }
        /*******************************************/
        /* Se comento para que no se agrandara el iframe */
        //var nih = 0;
        //nih = parseInt(window.parent.__IframeHeight.substring(0, window.parent.__IframeHeight.length - 2));
        
        //if (nih < (divheight + imgt)) {
        //    window.parent.ResizerPantallaIframe(window.parent.__IframeWidth, (imgt + (divheight * 1.1)) + "px");
        //}
        /*******************************************/
    }

    //alert(bodyh + " imgt " + imgt + " divheight " + divheight + " dcleft " + dctop);

    divcal.style.top = dctop + "px";
    divcal.style.left = dcleft + "px";
    /*******************************************/

    divcal.style.width = divwidth + "px";
    divcal.style.height = divheight + "px";

    __CalContenedor = divcal.id
    document.body.appendChild(divcal);

    var hoy = new Date();
    var hoyanio = hoy.getFullYear();
    var hoymes = hoy.getMonth();
    var hoydia = hoy.getDay();

    GenerarCalendario(hoyanio, hoymes, hoydia);
}

function daysInMonth(humanMonth, year) {
    return new Date(year || new Date().getFullYear(), humanMonth, 0).getDate();
}

function getLastDay(anio, mes, dia) {

    var fecha = new Date(anio, mes, dia);
    var fechaanio = fecha.getFullYear();
    var fechames = fecha.getMonth();
    var fechadia = fecha.getDay();
    var ultdia = 0;

    ultdia = daysInMonth(mes + 1, anio);

    return ultdia;
}

function sombrear(otd,sw) {

    if (sw == true) { otd.style.backgroundColor = "#FFF"; }
    else { otd.style.backgroundColor = "#e7f0f7"; }
}

function GenerarCalendario(anio, mes, dia) {

    var hoy = new Date();
    var hoyanio = hoy.getFullYear();
    var hoymes = hoy.getMonth();
    var hoydia = hoy.getDate();

    var fecha = new Date(anio, mes, dia);
    var fechaanio = fecha.getFullYear();
    var fechames = fecha.getMonth();
    var fechadia = fecha.getDate();

    var fechadiasem = fecha.getDay();

    var fecha2 = new Date(anio, mes, 1);
    var fecha2anio = fecha2.getFullYear();
    var fecha2mes = fecha2.getMonth();
    var fecha2dia = fecha2.getDate();

    var fecha2diasem = fecha2.getDay();

    var ArrMes = new Array("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Setiembre", "Octubre", "Noviembre", "Diciembre");
    var ArrDias = new Array("Lunes", "Martes", "Miercoles", "Jueves", "Viernes", "Sabado", "Domingo");

    var ultdia = getLastDay(anio, mes, dia);

    var str = "";

    var MesAnterior = "";
    var MesActual = "";
    var MesPosterior = "";
    var nMesAnterior = 0;
    var nMesActual = 0;
    var nMesPosterior = 0;
    var nAnioAnterior = 0;
    var nAnioActual = 0;
    var nAnioPosterior = 0;

    nMesAnterior = mes;
    nMesActual = mes;
    nMesPosterior = mes;
    nAnioAnterior = anio;
    nAnioActual = anio;
    nAnioPosterior = anio;

    MesAnterior = ArrMes[mes];
    MesActual = ArrMes[mes];
    MesPosterior = ArrMes[mes];
    if (mes == 0) { MesAnterior = ArrMes[ArrMes.length - 1]; nMesAnterior = ArrMes.length - 1; nAnioAnterior = nAnioActual - 1; }
    else { MesAnterior = ArrMes[mes - 1]; nMesAnterior = mes - 1; }
    if (mes + 1 == ArrMes.length) { MesPosterior = ArrMes[0]; nMesPosterior = 0; nAnioPosterior = nAnioActual + 1; }
    else { MesPosterior = ArrMes[mes + 1]; nMesPosterior = mes + 1; }

    str += "<table border='0' cellpadding='0' cellspacing='0' width='100%'>"
    str += "<tr>";
    str += "<td align='right'>";
    str += "<img id='btnc' title='Cerrar' height='25px' border='0' src='../../Images/x.png' style='cursor:pointer; position:relative; top:11px; left:13px' onclick='CerrarCalendario()' />";
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td>";

    str += "<table class='cajaCeleste' border='0' cellpadding='0' cellspacing='0' width='100%' style='padding-left:3px; padding-right:3px'>"
    str += "<tr>";
    str += "<td align='center' colspan='3' style='padding-left:5px; padding-right:5px; cursor:default'>";
    str += "<span style='color:#00529b; font-size:14px; font-weight:bold'>" + MesActual.toUpperCase() + " " + nAnioActual + "</span>";
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td align='left' style='padding-left:5px; padding-right:5px; cursor:pointer' onclick='GenerarCalendario("+nAnioAnterior+","+nMesAnterior+","+fechadia+")'>";
    str += "<span style='color:#00529b; font-size:11px; font-weight:bold'>" + MesAnterior.substring(0, 3) + "</span>";
    str += "</td>";
    str += "<td align='right' style='padding-left:5px; padding-right:5px; cursor:pointer' onclick='GenerarCalendario(" + nAnioPosterior + "," + nMesPosterior + "," + fechadia + ")'>";
    str += "<span style='color:#00529b; font-size:11px; font-weight:bold'>" + MesPosterior.substring(0, 3) + "</span>";
    str += "</td>";
    str += "</tr>";
    str += "<tr>";
    str += "<td align='center' colspan='3'>";
    /*******************************************************************************************/


    var cols = 7;
    var ncol = 0;
    var nrow = 0;
    var ndia = 0;
    var tdspace = 0;
    if (fecha2diasem == 0) { tdspace = 6; }
    else { tdspace = fecha2diasem - 1; }

    str += "<table border='0' cellpadding='1' cellspacing='1' width='100%' >"
    str += "<tr>";
    for (a = 0; a < ArrDias.length; a++) {
        str += "<td>";
        str += "<span style='cursor:default; font-size:8pt'>" + ArrDias[a].substring(0, 3) + "</span>";
        str += "</td>";
    }
    str += "</tr>"
    for (a = 0; a < ultdia + tdspace; a++) {
        if (ncol == 0) { str += "<tr>"; }
        ncol += 1;
        if (a >= (tdspace)) {
            if (ndia + 1 == hoydia && hoymes == fechames && hoyanio == fechaanio) {
                str += "<td style='cursor:pointer' onmouseover='sombrear(this,true)' onmouseout='sombrear(this,false)' onclick='getCalFecha(" + anio + "," + (mes + 1) + "," + (ndia + 1) + ")'>";
                str += "<span style='font-size:8pt; font-weight:bold; color:#000'>" + (ndia + 1) + "</span>";
                str += "</td>";
            }
            else {
                str += "<td style='cursor:pointer' onmouseover='sombrear(this,true)' onmouseout='sombrear(this,false)' onclick='getCalFecha(" + anio + "," + (mes + 1) + "," + (ndia + 1) + ")'>";
                str += "<span style='font-size:8pt'>" + (ndia + 1) + "</span>";
                str += "</td>";
            }
            ndia++;
        }
        else {
            str += "<td>";
            str += "";
            str += "</td>";
        }
        if (ncol == (cols)) { str += "</tr>"; ncol = 0; }
    }
    str += "</table>";


    /*******************************************************************************************/
    str += "</td>";
    str += "</tr>";
    str += "</table>";

    str += "</td>";
    str += "</tr>";
    str += "</table>";

    document.getElementById(__CalContenedor).innerHTML = str;
}

function getCalFecha(anio, mes, dia) {
    var strfecha = "";
    if (dia < 10) { strfecha += "0" + dia + "/"; }
    else { strfecha += dia + "/"; }
    if (mes < 10) { strfecha += "0" + mes + "/"; }
    else { strfecha += mes + "/"; }
    strfecha += anio;
    if (document.getElementById(__CalTextBox)) {
        document.getElementById(__CalTextBox).value = "";
        document.getElementById(__CalTextBox).focus();
        document.getElementById(__CalTextBox).value = strfecha;                        
    }
    else {
        alert("No existe " + __CalTextBox);
    }
    CerrarCalendario();
}

/*******************************************************************************************/
/*************************   VALIDACION DE BOTONES POPUP   *********************************/
/*******************************************************************************************/


function CCSoloNumeros() {
    var sw = true; var e; e = window.event;
    tecla = (document.all) ? e.keyCode : e.which; // 2
    if (tecla == 8) return true; // 3
    patron = /[0-9\s]/; // 4
    te = String.fromCharCode(tecla); // 5
    sw = patron.test(te); // 6
    if (tecla == 32) { sw = false; } //
    if (sw == false)
    { window.event.keyCode = 0; }
}


/*******************************************************************************************/
/*******************************   VENTANA PROVEEDOR   *************************************/
/*******************************************************************************************/

function btnBuscarProveedor(contenedor) {
    var root = "";
    var pagina = "";
    var w = "95%";
    var h = "100%";
    var str = "";
    str += "<table border='0' cellpadding='0' cellspacing='0'>";
    str += "<tr>";
    str += "<td style='padding-right:3px'>";
    str += "<input runat='server' ID='txtPROVCodigoProveedor' name='txtPROVCodigoProveedor' style='display:; width:100px' class='formularios' maxlength='11' onkeypress='CCSoloNumeros()' onpaste='javascript:ValidaSoloNumeroCopiar(this)'>";
    str += "<input runat='server' ID='txtPROVNombreAbr' name='txtPROVNombreAbr' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtPROVDireccion' name='txtPROVDireccion' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtPROVDistrito' name='txtPROVDistrito' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtPROVCiudad' name='txtPROVCiudad' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtPROVTelefono_1' name='txtPROVTelefono_1' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtPROVTelefono_2' name='txtPROVTelefono_2' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtPROVNumeroCuentaSoles' name='txtPROVNumeroCuentaSoles' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtPROVNumeroCuentaDolares' name='txtPROVNumeroCuentaDolares' style='display:none' class='formularios'>";
    str += "</td>";
    str += "<td>";
    str += "<img id='imgPROVBuscarProveedor' alt='Buscar Proveedor' src='../../Images/ico_busca.png' width='21' height='21' style='cursor:pointer;' onclick=paginaup('../Common/','frmBuscarProveedor.aspx','620px','500px') />";
    str += "</td>";
    str += "<td id='tdtxtCCDescripcion' style='display:none'>";
    str += "<input runat='server' ID='txtPROVRazonSocial' name='txtPROVRazonSocial' readonly='readonly' onfocus='this.blur()' style='width:290px; cursor:default'>";
    str += "</td>";
    str += "</tr>";
    str += "</table>";
    //document.write(str);
    if (document.getElementById(contenedor)) {
        document.getElementById(contenedor).innerHTML = str;
    }
}

function btnCloseProveedor() {
    window.parent.pantallafondo("frmBuscarProveedor.aspx", false);
    window.parent.pantallaiframe("", "frmBuscarProveedor.aspx", "", "", false);
}

function setCodigoProveedor_Parent(val) {
    if (window.parent.document.getElementById("txtPROVCodigoProveedor")) { window.parent.document.getElementById("txtPROVCodigoProveedor").value = val; }
    /*
    * @author Rodriguez Jose
    * Actualizacion: Se modifico para que guarde en un hidden el valor del ruc en caso se necesite deshabilitar el campo de ruc
    */
    if (window.parent.document.getElementById("hdnRucProveedor")) {
        if (window.parent.document.getElementById("hdnRucProveedor").value != val) {
            window.parent.document.getElementById("hdnRucProveedor").value = val;
            window.parent.OcultarZona();
        }
    }
    if (window.parent.document.getElementById("hdnZonaActiva")) {
        if (window.parent.document.getElementById("hdnRucProveedor1")) {
            if (window.parent.document.getElementById("hdnZonaActiva").value == "page1") {
                if (window.parent.document.getElementById("hdnRucProveedor1").value != val) {
                    window.parent.document.getElementById("hdnRucProveedor1").value = val;                
                }                
            }
        }
        if (window.parent.document.getElementById("hdnRucProveedor2")) {
            if (window.parent.document.getElementById("hdnZonaActiva").value == "page2") {
                if (window.parent.document.getElementById("hdnRucProveedor2").value != val) {
                    window.parent.document.getElementById("hdnRucProveedor2").value = val;
                }                
            }
        }
    }  
    /*
    * Fin actualizacion
    */
}
function setNombreAbr_Parent(val) {
    if (window.parent.document.getElementById("txtPROVNombreAbr")) { window.parent.document.getElementById("txtPROVNombreAbr").value = val; }
}
function setDireccion_Parent(val) {
    if (window.parent.document.getElementById("txtPROVDireccion")) { window.parent.document.getElementById("txtPROVDireccion").value = val; }
}
function setDistrito_Parent(val) {
    if (window.parent.document.getElementById("txtPROVDistrito")) { window.parent.document.getElementById("txtPROVDistrito").value = val; }
}
function setCiudad_Parent(val) {
    if (window.parent.document.getElementById("txtPROVCiudad")) { window.parent.document.getElementById("txtPROVCiudad").value = val; }
}
function setTelefono_1_Parent(val) {
    if (window.parent.document.getElementById("txtPROVTelefono_1")) { window.parent.document.getElementById("txtPROVTelefono_1").value = val; }
}
function setTelefono_2_Parent(val) {
    if (window.parent.document.getElementById("txtPROVTelefono_2")) { window.parent.document.getElementById("txtPROVTelefono_2").value = val; }
}
function setNumeroCuentaSoles_Parent(val) {
    if (window.parent.document.getElementById("txtPROVNumeroCuentaSoles")) { window.parent.document.getElementById("txtPROVNumeroCuentaSoles").value = val; }
}
function setNumeroCuentaDolares_Parent(val) {
    if (window.parent.document.getElementById("txtPROVNumeroCuentaDolares")) { window.parent.document.getElementById("txtPROVNumeroCuentaDolares").value = val; }
}


var parentPROVRazonSocial;
function setRazonSocial_Parent(val) {
    if (window.parent.document.getElementById("txtPROVRazonSocial"))
    { window.parent.document.getElementById("txtPROVRazonSocial").value = val; }
    /*
    * @author Rodriguez Jose
    * Actualizacion: Se modifico para que guarde en un hidden el valor de la razon social en caso se necesite deshabilitar el campo de ruc
    */
    if (window.parent.document.getElementById("hdnRazonSocial")) { window.parent.document.getElementById("hdnRazonSocial").value = val; }
    
    /*
    * Fin actualizacion
    */
    if (window.parent.document.getElementById(window.parent.parentPROVRazonSocial))
    { window.parent.document.getElementById(window.parent.parentPROVRazonSocial).value = val; }    
}

function ShowPROVRazonSocial() {
    if (document.getElementById("tdtxtPROVRazonSocial")) {
        document.getElementById("tdtxtPROVRazonSocial").style.paddingLeft = "5px";
        document.getElementById("tdtxtPROVRazonSocial").style.display = "";
    }
}

function ShowPROVRazonSocialInput(strinput) {
    parentPROVRazonSocial = strinput;
}

function ShowPROVRazonSocialInput_Parent(strinput, val) {
    if (window.parent.document.getElementById(strinput)) {
        window.parent.document.getElementById(strinput).value = val;
    }
}

function getCodigoProveedor(val) {
    return document.getElementById("txtPROVCodigoProveedor").value;
}

function BloquearPROVCodigoProveedor(sw) {
    if (document.getElementById("txtPROVCodigoProveedor")) {
        var oRuc=document.getElementById("txtPROVCodigoProveedor");
        if (sw == true) {
            oRuc.readOnly = true;
            oRuc.style.cursor = "default";
            oRuc.onclick = function () {
                oRuc.blur();
            }
            oRuc.onmouseup = function () {
                oRuc.blur();
            }
            oRuc.onselectstart = function () {
                return false;
            }
            oRuc.onfocus = function () {
                oRuc.blur();
            }
            if (document.getElementById("imgPROVBuscarProveedor")) {
                document.getElementById("imgPROVBuscarProveedor").style.display = "none";
            }
            document.getElementById("txtPROVCodigoProveedor").style.color = "#666";
        }
        else {
            oRuc.readOnly = false;
            oRuc.style.cursor = "";
            if (document.getElementById("imgPROVBuscarProveedor")) {
                document.getElementById("imgPROVBuscarProveedor").style.display = "";
            }
        }
    }
}

var __PROVidframe = "__iGetProveedor";
var __PROVidbloqueo = "__divblanco";

function PROVBloquearPantalla(sw) {
    var idfondo = __PROVidframe + "block";
    if (sw == false) {
        if (document.getElementById(idfondo))
        { document.body.removeChild(document.getElementById(idfondo)); }
    }
    else {
        var bgb = document.createElement("div");
        bgb.id = idfondo;
        bgb.style.backgroundColor = "#FFFFFF";
        bgb.style.position = "fixed";
        bgb.style.top = "0px";
        bgb.style.left = "0px";
        bgb.style.width = "100%";
        bgb.style.height = "100%";
        bgb.style.opacity = "0.8";
        bgb.style.filter = "alpha(opacity=80)";
        document.body.appendChild(bgb);
    }
}

function PROVCargarProveedor(strRuc, InputRS) {
    var oframe;
    var obloqueo;
    if (document.getElementById(__PROVidframe)) {
        oframe = document.getElementById(__PROVidframe);
        oframe.src = "../Common/frmBuscarProveedor.aspx?Accion=GetInfo&CodigoProveedor=" + strRuc + "&InputRS=" + InputRS;
    }
    else {
        oframe = document.createElement("iframe");
        oframe.id = __PROVidframe;
        oframe.src = "../Common/frmBuscarProveedor.aspx?Accion=GetInfo&CodigoProveedor=" + strRuc + "&InputRS=" + InputRS;
        oframe.style.width = "200px";
        oframe.style.height = "150px";
        oframe.style.display = "none";
        document.body.appendChild(oframe);
    }
}

var __PROVCodigoProveedorTEMP = "";
var __PROVCodigoProveedorVALIDO = true;

function ValidarPROVCodigoProveedor() {
    if (document.getElementById("txtPROVCodigoProveedor")) {
        var oRuc = document.getElementById("txtPROVCodigoProveedor");
        oRuc.onblur = function () {
            if (oRuc.value.length >= 11) {
                if (__PROVCodigoProveedorVALIDO == false && __PROVCodigoProveedorTEMP == oRuc.value) {
                    alert("El RUC ingresado no existe");
                    oRuc.focus();
                }
                if (__PROVCodigoProveedorTEMP != oRuc.value) {
                    __PROVCodigoProveedorTEMP = oRuc.value;
                    PROVBloquearPantalla(true);

                    var strinputrs = parentPROVRazonSocial;
                    if (strinputrs == "") { strinputrs = "txtPROVRazonSocial"; }

                    PROVCargarProveedor(oRuc.value, strinputrs);
                }
            }
            else {
                if (oRuc.value.length > 0) {
                    alert("Ruc Inválido");
                    oRuc.focus();
                    __PROVCodigoProveedorVALIDO = true;
                }
            }
        }
    }
}

/*******************************************************************************************/
/****************************   VENTANA CUENTA CONTABLE   **********************************/
/*******************************************************************************************/

//Request.Form.Item("txtCuentaContable")
//Request.Form.Item("txtCuentaContable_Codigo")
//Request.Form.Item("txtCuentaContable_Descp")
//Request.Form.Item("txtCuentaContable_DescpCorta")

function btnBuscarCuentaContable(contenedor) {
    var root = "";
    var pagina = "";
    var w = "95%";
    var h = "100%";
    var str = "";
    str += "<table border='0' cellpadding='0' cellspacing='0'>";
    str += "<tr>";
    str += "<td style='padding-right:3px'>";
    str += "<input runat='server' ID='txtCCCodigoCuenta' name='txtCCCodigoCuenta' style='display:; width:100px' class='formularios' maxlength='10' onkeypress='CCSoloNumeros()' readonly='true'>";
    str += "<input runat='server' ID='txtCCCodigoPortafolio' name='txtCCCodigoPortafolio' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtCCCodigoAnio' name='txtCCCodigoAnio' style='display:none' class='formularios'>";
    str += "<input runat='server' ID='txtCCEsImputable' name='txtCCEsImputable' style='display:none' class='formularios'>";
    str += "</td>";
    str += "<td>";
    str += "<img alt='Buscar Cuenta Contable' src='../../Images/ico_busca.png' width='21' height='21' style='cursor:pointer;' onclick=paginaup('../Common/','frmBuscarCuentaContable.aspx','620px','415px') />";
    str += "</td>";
    str += "<td id='tdtxtCCDescripcion' style='display:none'>";
    str += "<input runat='server' ID='txtCCDescripcion' name='txtCCDescripcion' readonly='readonly' onfocus='this.blur()' style='width:290px; cursor:default'>";
    str += "</td>";
    str += "</tr>";
    str += "</table>";
    //document.write(str);
    if(document.getElementById(contenedor)) {
    document.getElementById(contenedor).innerHTML = str;}
}


function btnCloseCuentaContable() {
    window.parent.pantallafondo("frmBuscarCuentaContable.aspx", false);
    window.parent.pantallaiframe("", "frmBuscarCuentaContable.aspx", "", "", false);
}


function setCodigoPortafolio_Parent(val) {
    if (window.parent.document.getElementById("txtCCCodigoPortafolio")){window.parent.document.getElementById("txtCCCodigoPortafolio").value = val; }
}
function setCodigoAnio_Parent(val) {
    if (window.parent.document.getElementById("txtCCCodigoAnio")){ window.parent.document.getElementById("txtCCCodigoAnio").value = val; }
}
function setCodigoCuenta_Parent(val) {
    if (window.parent.document.getElementById("txtCCCodigoCuenta")){ window.parent.document.getElementById("txtCCCodigoCuenta").value = val; }
}
var parentCCDescripcion;
function setDescripcion_Parent(val) {
    if (window.parent.document.getElementById("txtCCDescripcion"))
    { window.parent.document.getElementById("txtCCDescripcion").value = val; }
    if (window.parent.document.getElementById(window.parent.parentCCDescripcion))
    { window.parent.document.getElementById(window.parent.parentCCDescripcion).value = val; }
}
function setEsImputable_Parent(val) {
    if (window.parent.document.getElementById("txtCCEsImputable")){ window.parent.document.getElementById("txtCCEsImputable").value = val; }
}

function ShowCCDescripcion() {
    if (document.getElementById("tdtxtCCDescripcion")) {
        document.getElementById("tdtxtCCDescripcion").style.paddingLeft = "5px";
        document.getElementById("tdtxtCCDescripcion").style.display = "";
    }
}

function ShowCCDescripcionInput(strinput) {
    parentCCDescripcion = strinput;
}

/*******************************************************************************************/
/******************************   VENTANA EMERGENTE   **************************************/
/*******************************************************************************************/

var __ZIndexPantalla = 500;
var __IframeWidth = "";
var __IframeHeight = "";
var __IframePagina = "";
var __IframeId = "";

var iframename = "ipagina";

function paginaup(root, pagina, w, h, opcscroll) {
    pantallafondo(iframename, true);
    pantallaiframe(root, pagina, w, h, true, opcscroll);
}
function cerrarpaginaup() {
    window.parent.pantallafondo(window.parent.__IframePagina, false);
    window.parent.pantallaiframe("", window.parent.__IframePagina, "0px", "0px", false);
    //window.parent.document.getElementById("btnc").click();
}

function ResizerPantallaIframeClose() {
    if (document.getElementById(__IframeId)) {

        document.getElementById(__IframeId).style.width = __IframeWidth;
        document.getElementById(__IframeId).style.height = __IframeHeight;

        if (window.parent.document.getElementById("btnc")) {
            window.parent.ResizerPantallaIframe(__IframeWidth, __IframeHeight);
        }
    }
}

function ResizerPantallaIframe(w, h) {
    if (document.getElementById(__IframeId)) {
        var nw = 0;
        if (w != "" && w.length > 2) { nw = parseInt(w.substring(0, w.length - 2)); }
        var nh = 0;
        if (h != "" && h.length > 2) { nh = parseInt(h.substring(0, h.length - 2)); }

        nw = nw + (nw * 0.1);
        nh = nh + (nh * 0.1);

        document.getElementById(__IframeId).style.width = nw + "px";
        document.getElementById(__IframeId).style.height = nh + "px";

        if (window.parent.document.getElementById("btnc")) {
            window.parent.ResizerPantallaIframe(nw + "px", nh + "px");
        }
    }
}

function pantallaiframe(root, pagina, w, h, sw, opcscroll) {
    var frameid = iframename + "_ifp";
    if (sw == false) {
        if (document.getElementById(frameid)) {
            if (window.parent.document.getElementById("btnc")) {
                window.parent.document.getElementById("btnc").style.display = "";

                window.parent.ResizerPantallaIframeClose();
            }

            var inputs = window.parent.document.getElementsByTagName("input");
            for (a = 0; a < inputs.length; a++) {
                if (inputs[a].id.substring(0, 2) != "__") {
                    try { inputs[a].focus(); inputs[a].blur(); }
                    catch (err) { }
                }
            }

            pantallafondo(iframename, false);
            document.body.removeChild(document.getElementById(frameid));
        }
    }
    else {

        var bodywidth = 0;
        bodywidth = parseInt(document.body.scrollWidth);
        var bodyheight = 0;
        bodyheight = parseInt(document.body.scrollHeight);
        var divtop = 0;
        var divHeightLimit = 450;

        var nw = 0;
        if (w != "" && w.length > 2) { nw = parseInt(w.substring(0, w.length - 2)); }
        var nh = 0;
        if (h != "" && h.length > 2) { nh = parseInt(h.substring(0, h.length - 2)); }

        /* Establecemos nuevas medidas para la PAGINAUP padre */
        var newWidth = "";
        var newHeight = "";

        if (nw != 0) { newWidth = (nw + (nw * 0.1)) + "px"; }
        if (nh != 0) { newHeight = (nh + (nh * 0.2)) + "px"; }

        if (window.parent.document.getElementById("btnc")) {
            window.parent.document.getElementById("btnc").style.display = "none";
            if (newWidth != "" && newHeight != "") {
                window.parent.ResizerPantallaIframe(newWidth, newHeight);
            }
        }
        /* ************************************************** */

        if (nh > divHeightLimit) {
            divtop = bodyheight + 10;
        }
        else {
            divtop = bodyheight - (nh * 0.35);
            if (bodyheight < divHeightLimit) {
                divtop = bodyheight - (nh * 0.20);
            }
        }
            
        if (window.parent.document.getElementById("btnc")) {
            //divtop = bodyheight + 17;
            divtop = bodyheight;
        }

        var ifp = document.createElement("div");
        ifp.id = frameid;
        ifp.style.position = "relative";
        ifp.style.top = "-" + divtop + "px";
        ifp.style.left = "0px";
        ifp.style.width = "100%";
        ifp.style.height = "100%";
        //ifp.style.backgroundImage = "url('../../Images/bk_modal.png')";

        var swbgb = document.createElement("input");
        swbgb.id = "_swbgb";
        swbgb.type = "Hidden";
        var nbgb = 1;

        if (window.parent.document.getElementById(swbgb.id)) {
            nbgb = parseInt(window.parent.document.getElementById(swbgb.id).value) + 1;
            swbgb.value = nbgb;
        }

        __IframePagina = iframename;
        __IframeId = iframename + "_content";
        __IframeWidth = w;
        __IframeHeight = h;

        ifp.style.zIndex = (__ZIndexPantalla * nbgb) + 100;

        if (w == "") { w = "80%"; }
        //if (h == "") { h = "90%"; }   //  Más adelante se controla el tamaño de la página

        var str = "";
        str += "<table border='0' cellpadding='0' cellspacing='0' width='100%' height='100%'>";
        str += "<tr>";
        str += "<td width='100%' height='100%' align='center' valign='top'>";
        //str += "<br />";

        str += "<table border='0' cellpadding='0' cellspacing='0' style='background-color:'>";
        str += "<tr>";
        str += "<td align='right'>";
        str += "<div style='position:relative;top:22px;left:7px'>";
        str += "<img id='btnc' border='0' src='../../Images/x.png' style='cursor:pointer' onclick=pantallaiframe('" + root + "','" + pagina + "','" + w + "','" + h + "',false) />";
        str += "</div>";
        //str += "<div title='Cerrar' style=position:fixed;cursor:pointer;background-image:url('../Images/x.png');width:25px;height:30px onclick=pantallaiframe('" + root + "','" + pagina + "',false) ></div>";
        str += "</td>";
        str += "</tr>";
        str += "<tr>";
        str += "<td style='padding-left:0px; padding-right:0px; height:100%; background-color:#FFF; border-style:solid;border-width:3px; border-color:#000' valign='top'>";

        var scrolling = "no";
        if (opcscroll == 2) { scrolling = "auto"; }
        if (opcscroll == 1) { scrolling = "yes"; }
        //alert(scrolling);

        str += "<div id='" + iframename + "_content' style='width:" + w + ";height:" + h + "; padding:2px' >";
        str += "<iframe style='width:100%; height:100%' frameborder='0' scrolling='" + scrolling + "' id='" + iframename + "_frame' src='" + root + pagina + "' onload=ReSizerPaginaUp(this,'" + w + "','" + h + "') ></iframe>";
        str += "</div>";

        str += "</td>";
        str += "</tr>";
        str += "</table>";

        str += "</td>";
        str += "</tr>";
        str += "</table>";

        ifp.innerHTML = str;

        if (document.getElementById(ifp.id))
        {  }
        else {
            document.body.appendChild(ifp);
        }

        document.body.scrollIntoView(true);

    }
}

function ReSizerPaginaUp(objIframe, w, h) {
    var pageHeigth = 0;
    var pageWidth = 0;
    if (h == "") {
        pageHeigth = parseInt(objIframe.contentWindow.document.body.scrollHeight);
        __IframeHeight = (pageHeigth + (pageHeigth * 0.12)) + "px";

        document.getElementById(__IframeId).style.height = __IframeHeight;

        h = __IframeHeight; //  Establecemos nueva Altura de la página

        var nw = 0;
        if (w != "" && w.length > 2) { nw = parseInt(w.substring(0, w.length - 2)); }
        var nh = 0;
        if (h != "" && h.length > 2) { nh = parseInt(h.substring(0, h.length - 2)); }

        /* Establecemos nuevas medidas para la PAGINAUP padre */
        var newWidth = "";
        var newHeight = "";

        //if (nw != 0) { newWidth = (nw + (nw * 0.1)) + "px"; }
        if (nw != 0) { newWidth = w; }  //para no aumentar el ancho
        if (nh != 0) { newHeight = (nh + (nh * 0.15)) + "px"; }

        if (window.parent.document.getElementById("btnc")) {
            window.parent.document.getElementById("btnc").style.display = "none";
            if (newWidth != "" && newHeight != "") {
                window.parent.ResizerPantallaIframe(newWidth, newHeight);
            }
        }
    }

}

function pantallafondo(id, sw) {
    var fondoid = id + "_bgb";
        if (sw == false) {
            if (document.getElementById(fondoid))
            { document.body.removeChild(document.getElementById(fondoid)); }
        }
        else {
            var bgb = document.createElement("div");
            bgb.id = fondoid;
            bgb.style.backgroundColor = "#000000";
            bgb.style.position = "fixed";
            bgb.style.top = "0px";
            bgb.style.left = "0px";
            bgb.style.width = "100%";
            bgb.style.height = "100%";
            //bgb.style.backgroundImage = "url('../Images/bk_modal.png')";
            bgb.style.opacity = "0.7";
            bgb.style.filter = "alpha(opacity=70)";

            var swbgb = document.createElement("input");
            swbgb.id = "_swbgb";
            swbgb.type = "Hidden";
            var nbgb = 1;
            if (window.parent.document.getElementById(swbgb.id)) {
                nbgb = parseInt(window.parent.document.getElementById(swbgb.id).value) + 1;
                swbgb.value = nbgb;
                bgb.appendChild(swbgb);
            }
            else {
                swbgb.value = nbgb;
                bgb.appendChild(swbgb);
            }

            bgb.style.zIndex = __ZIndexPantalla * nbgb;

            if (document.getElementById(fondoid))
            {  }
            else {
                document.body.appendChild(bgb);
            }
        }
}


/*******************************************************************************************/
/******************************   IFRAME ADAPTABLE   ***************************************/
/*******************************************************************************************/

function iframeresizer(iframe, h1, w1) {
    var h = parseInt(iframe.contentWindow.document.body.scrollHeight);
    var w = parseInt(iframe.contentWindow.document.body.scrollWidth);
    h = h * 1.1; w = w * 1.1;
    if (h1 == "") { iframe.style.height = h + "px"; }
    else { iframe.style.height = h1; }
    //iframe.style.width = w + "px";
    if (w1 == "") { iframe.style.width = "100%"; }
    else { iframe.style.width = w1; }
}


/*******************************************************************************************/
/**********************************   GRIDVIEW   *******************************************/
/*******************************************************************************************/

var objgrilla = null;
function grilla(idgrilla) {
    if (document.getElementById(idgrilla)) {
        objgrilla = document.getElementById(idgrilla);
    }
    else if (window.parent.document.getElementById(idgrilla)) {
        objgrilla = window.parent.document.getElementById(idgrilla);
    }
    else
    { alert("No existe " + idgrilla); }
}
function celda() {
    this.row = "";
    this.col = "";
    this.id = "";
    this.celdastyle = "";
    this.celdaclass = "";
    this.rowstyle = "";
    this.rowclass = "";
    this.colstyle = "";
    this.colclass = "";
    this.contenido = "";
    this.eventos = "";
    this.etiqueta = "";
}

var objTabla = new Array();

function setCelda(r1, c1, id, cest, cecl, rost, rocl, cost, cocl, con, eve, eti) {
    var oc = new celda();
    oc.row = r1;
    oc.col = c1;
    oc.id = id;
    oc.celdastyle = cest;
    oc.celdaclass = cecl;
    oc.rowstyle = rost;
    oc.rowclass = rocl;
    oc.colstyle = cost;
    oc.colclass = cocl;
    oc.contenido = con;
    oc.etiqueta = eti;
    var swCelda = true;
    var ind = 0;
    for (a = 0; a < objTabla.length; a++) {
        if (objTabla[a].col == c1 && objTabla[a].row == r1) { swCelda = false; ind = a; }
    }
    if (objgrilla != null) {
        if (swCelda == true) {
            objTabla[objTabla.length] = oc;
        }
        else {
            objTabla[ind] = oc;
        }
    }
}

function setCeldaTitulo_1(r1, c1, con, cest) {
    setCelda(r1, c1, "", cest, "", "", "", "", "", con, "", "th");
}
function setCelda_1(r1, c1, con) {
    setCelda(r1, c1, "", "", "", "", "", "", "", con, "", "td");
}
function setCelda_2(r1, c1, con, rocl) {
    setCelda(r1, c1, "", "", "", "", rocl, "", "", con, "", "td");
}

function getCelda(r2, c2) {
    var celda = null;
    for (a = 0; a < objTabla.length; a++) {
        if (objTabla[a].col == c2 && objTabla[a].row == r2) { celda = objTabla[a]; }
    }
    return celda;
}

function makeTable(estilo) {
    var str = "";
    str += "<table " + estilo + " >";
    swFila = true; f = 0;
    while (swFila == true) {
        swFila = false;
        var filaclase = "";
        var fila = 0;
        for (a = f; a < objTabla.length; a++)
        { if (objTabla[a].row == f) { swFila = true; fila = a; filaclase = objTabla[a].rowclass; } }
        if (swFila == true) {
            str += "<tr style='" + objTabla[fila].rowstyle + "' class='" + filaclase + "' >";
            for (a = 0; a < objTabla.length; a++) {
                if (objTabla[a].row == f) {
                    str += "<" + objTabla[a].etiqueta + " id='" + objTabla[a].id + "' style='" + objTabla[a].colstyle + "' class='" + objTabla[a].colclass + "' >";
                    str += objTabla[a].contenido;
                    str += "</" + objTabla[a].etiqueta + ">";
                }
            }
            str += "</tr>";
            f++;
        }
    }
    str += "</table>";
    objgrilla.innerHTML = str;
}

/*******************************************************************************************/
/*******************************************************************************************/
/*******************************************************************************************/